/*
 * WA
 * knapsack problem and I haven't complete this problem~~!!
 **/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) > (b) ? (b) : (a))

int k;
int blocks[400][3];
unsigned short int f[32034072 + 100];
int end, block;

int comp(const void *a, const void *b)
{
	return (*((int *)a + 1) - *((int *)b + 1));
}
int main(int argc, char **argv)
{
	int i, j, m, highest = 0, t;

	scanf("%d", &k);
	for (i = 0; i < k; i++) {
		scanf("%d %d %d", &blocks[i][0], &blocks[i][1], &blocks[i][2]);
		blocks[i][2] = min(blocks[i][1] / blocks[i][0], blocks[i][2]);
	}
	qsort(blocks, k, sizeof(int) * 3, comp);
	f[0] = 0;
	for (i = 1; i <= blocks[0][2]; i++) {
		f[i] = blocks[0][0] * i;
	}
	block = blocks[0][2] + 1;
	end = block;
	for (i = 1; i < k; i++) {
		for (j = 1; j <= blocks[i][2]; j++) {
			for (m = 0; m < block; m++) {
				t = f[m] + j * blocks[i][0];
				if (t > blocks[i][1])
					break;
				if (t > highest)
					highest = t;
				f[end + m] = t;
			}
			end += m;
		}
		block = end;
	}
	/*
	for (i = 0; i < end; i++) {
		if (highest < f[i])
			highest = f[i];
	}
	*/
	printf("%d\n", highest);
	return 0;
}
